<!-- subpkg_archive/list/index.vue -->
<script lang="ts" setup>
  import { getPatientListApi } from '@/api/patient'
  import type { PatientItem } from '@/types/patient'
  import { onShow } from '@dcloudio/uni-app'
  import { ref } from 'vue'

  const swipeOptions = ref([
    {
      text: '删除',
      style: {
        backgroundColor: '#dd524d',
        color: '',
        fontSize: '',
      },
    },
  ])
  const list = ref<PatientItem[]>([])
  onShow(async () => {
    const res = await getPatientListApi()
    list.value = res
  })
</script>

<template>
  <scroll-page>
    <view class="archive-page">
      <view class="archive-tips">最多可添加6人</view>

      <uni-swipe-action>
        <uni-swipe-action-item :right-options="swipeOptions" v-for="item in list" :key="item.id">
          <view class="archive-card active">
            <view class="archive-info">
              <text class="name">{{ item.name }}</text>
              <text class="id-card">{{
                item.idCard.replace(/^(\d{6})\d{8}(\d{4})$/, '$1*******$2')
              }}</text>
              <text class="default">默认</text>
            </view>
            <view class="archive-info">
              <text class="gender">{{ item.gender ? '男' : '女' }}</text>
              <text class="age">{{ item.age }}岁</text>
            </view>
            <navigator hover-class="none" class="edit-link" url="/subpkg_archive/form/form">
              <uni-icons type="icon-edit" size="20" color="#16C2A3" custom-prefix="iconfont" />
            </navigator>
          </view>
        </uni-swipe-action-item>

        <!-- <uni-swipe-action-item :right-options="swipeOptions">
          <view class="archive-card">
            <view class="archive-info">
              <text class="name">李富贵</text>
              <text class="id-card">321***********6164</text>
            </view>
            <view class="archive-info">
              <text class="gender">男</text>
              <text class="age">32岁</text>
            </view>
            <navigator hover-class="none" class="edit-link" url="/subpkg_archive/form/form">
              <uni-icons type="icon-edit" size="20" color="#16C2A3" custom-prefix="iconfont" />
            </navigator>
          </view>
        </uni-swipe-action-item> -->
      </uni-swipe-action>

      <!-- 添加按钮 -->
      <view v-if="list.length < 6" class="archive-card">
        <navigator class="add-link" hover-class="none" url="/subpkg_archive/form/form">
          <uni-icons color="#16C2A3" size="24" type="plusempty" />
          <text class="label">添加患者</text>
        </navigator>
      </view>
    </view>
  </scroll-page>
</template>

<style lang="scss">
  @import './list.scss';
</style>
